mini.parse();
var baseUrl = "http://localhost:8080/DSMP";
var grid=mini.get("grid1");
//分页控件
var pager = grid.getBottomPager();
var form= new mini.Form("#form1");
var qqq=[
    { "id": "0", "text": "未审核" },
    { "id": "1", "text": "审核通过" },
    { "id": "2", "text": "审核未通过" },
]
var www=[
    { "id": "0", "text": "空闲" },
    { "id": "1", "text": "有计划" },
    { "id": "2", "text": "忙碌" },
]
var eee=[
    { "id": "0-20", "text": "0-20" },
    { "id": "20-50", "text": "20-50" },
    { "id": "50-100", "text": "50-100" },
    { "id": "100-150", "text": "100-150" },
]
var applyState=mini.get("applyState");
// applyState.setData(qqq);
// var applyDate=mini.getByName("applyDate");
// applyDate.setData(www);
// var salary=mini.get("salary");
// salary.setData(eee);
(function(){
    request('0',pager.getPageSize());
})();


//跳转增加页面
function addRow(){
    mini.open({

        targetWindow: window,
        url:"Carapplication.html",
        title:"",
        height:700,
        width:1300,
        showMaxButton: true,
        showModal:Boolean,
        allowResize:Boolean,
        setReadOnly:false,
        onload: function () {

        },
        ondestroy: function (action) {
            if(action=="ok"){


            }
        }
    })
}


//跳转审核页面
function editRow(){
    var row = grid.getSelected();

    if (row) {
        mini.open({
            targetWindow: window,
            url: "Carreview.html",
            title: "用车审核",
            height: 600,
            width: 1300,
            showMaxButton: true,
            showModal: Boolean,
            allowResize: Boolean,
            setReadOnly: false,
            onload: function () {
                console.log(row.carApplyId)
                var iframe = this.getIFrameEl();//备份这个跨子页面窗口
                var data = {  action: "edit",row:row };//父传值给子页面
                iframe.contentWindow.SetData(data);//跨字串后页面渲染data
            },
            ondestroy: function (action) {
                    request('0',20)

            }
        })
    }else {
        mini.alert("请选中一行待审核记录")
    }
}

// function removeRow(){
//     if (grid.getSelected()) {
//         var caruUseInfoId = grid.getSelected().carUseInfoId;
//         var param = {params:caruUseInfoId}
//        var ids = JSON.stringify(param)
//         $.ajax({
//             url:baseUrl+"/carUseInfo/delCarUseInfo.do",
//             type:"post",
//             data:ids,
//             contentType: "application/json",
//             success:function (data) {
//                 mini.alert(data.msg)
//                 request();
//             }
//         })
//     }else{
//         mini.alert("请选中一行记录")
//     }
// }

//删除
function removeRow(){
    var rows=grid.getSelecteds();
    console.log(rows);
    var ids= '';
    rows.forEach(function(item){
        ids+=item.carUseInfoId+","
    })
    console.log(ids,'ids');
    var param = {params:ids}
    var params=JSON.stringify(param);
    if (rows.length>0) {      //当一条都不选时提示让选一条
        console.log(ids);
        $.ajax({
            url:baseUrl+"/carUseInfo/delCarUseInfo.do",
            data:params,
            contentType: "application/json",
            type:"post",
            success:function (data) {
                mini.alert(data.msg)
                request();
            }
        })
    }else{
        mini.alert("请至少选中一行记录")
    }
}


function request(pageIndex,pageSize){
    var pageIndex = pager.getPageIndex()
    var pageSize = pager.getPageSize();

    var pageObj = {
        current: pageIndex,
        size: pageSize,
    }

    var pageStr = JSON.stringify(pageObj);
    grid.loading('请稍后...');
    $.ajax({
        url: baseUrl+"/carUseInfo/getAllUseInfo.do",
        type: "post",
        contentType: "application/json",
        data:pageStr,
        success: function(data) {//请求成功完成后要执行的方法
            console.log(data);
            grid.setData(data.obj);
            pager.set({"totalCount": data.attributes.total})
        },
        error:function(data){
            mini.alert(cuole);
        }
    });
}
function find(){
    var aaa=form.getData();
    console.log(aaa);
    aaa=JSON.stringify(aaa);
    console.log(aaa);
    $.ajax({
        url: baseUrl+"/carUseInfo/getCarUseInfoByWhere.do",
        type: "post",
        contentType: "application/json",
        data:aaa,
        success: function(data) {//请求成功完成后要执行的方法
            console.log(data);
            grid.setData('');
            grid.setData(data.obj);
            mini.after(data.msg)
        },
        error:function(data){
            mini.alert(cuole);
        }
    });
}


//分页
grid.on("beforeload", function (e) {
    //阻止本来的翻页功能
    e.cancel = true;
    //当前页码
    var cunrrentPageIndex = grid.getPageIndex();
    //点击按钮之后的页码
    var pageIndex = e.data.pageIndex;
    //设置当前页数值
    pager.set({"pageIndex": pageIndex});
    //数据总数
    //var pageCount = pubPageCount;
    pager.set({"pageIndex": pageIndex});
    request(pageIndex + 1, pager.getPageSize());
});

//刷新
function onRefresh(e) {
    list(pager.getPageIndex(), pager.getPageSize());
}


//条件查询清空条件
function clean() {
    form.reset();
}